home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / jogos / spherical / Code / Game / hiscore.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2002-07-30  |  7.3 KB  |  225 lines

  1.  
  2. // Copyright (C) 2002 by Luigi Pino.  All Rights Reserved.
  3.  
  4. /***************************************************************************/
  5.  
  6. #include "../library/neurosis.h"
  7. #include "draw.h"
  8. #include "file_io.h"
  9. #include "hiscore.h"
  10. #include "initialize.h"
  11. #include "main.h"
  12. #include "menu_misc.h"
  13. #include "paddle.h"
  14. #include "sphere.h"
  15. #include "update.h"
  16.  
  17. /***************************************************************************/
  18.  
  19. extern High_Score_Struct    high_score_sphere;
  20. extern High_Score_Struct    high_score_time;
  21. extern Paddle_Struct            paddle_object[];
  22. extern Window_Class                window;
  23.  
  24. extern char                                high_score_name[];
  25.  
  26. /***************************************************************************/
  27.  
  28. int Compare_High_Score_Sphere(const void *p, const void *q)
  29.  
  30. {
  31.     int *p1 = (int*)(p);
  32.     int *q1 = (int*)(q);
  33.  
  34.     if (high_score_sphere.spheres[*p1] < high_score_sphere.spheres[*q1])
  35.         return (-1);
  36.     else if (high_score_sphere.spheres[*p1] > high_score_sphere.spheres[*q1])
  37.         return (1);
  38.     else
  39.         {
  40.             if (high_score_sphere.time[*p1] < high_score_sphere.time[*q1])
  41.                 return (1);
  42.             else if (high_score_sphere.time[*p1] > high_score_sphere.time[*q1])
  43.                 return (-1);
  44.             else
  45.                 return (0);
  46.         }
  47. }
  48.  
  49. /***************************************************************************/
  50.  
  51. int Compare_High_Score_Time(const void *p, const void *q)
  52.  
  53. {
  54.     int *p1 = (int*)(p);
  55.     int *q1 = (int*)(q);
  56.  
  57.     if (high_score_time.time[*p1] < high_score_time.time[*q1])
  58.         return (1);
  59.     else if (high_score_time.time[*p1] > high_score_time.time[*q1])
  60.         return (-1);
  61.     else
  62.         {
  63.             if (high_score_time.spheres[*p1] < high_score_time.spheres[*q1])
  64.                 return (-1);
  65.             else if (high_score_time.spheres[*p1] > high_score_time.spheres[*q1])
  66.                 return (1);
  67.             else
  68.                 return (0);
  69.         }
  70. }
  71.  
  72. /***************************************************************************/
  73.  
  74. void Save_High_Score_Verification()
  75.  
  76. {
  77.     bool    save_high_score = false;
  78.     FILE    *stream;
  79.     int        x1;
  80.  
  81.     stream = fopen("hiscore.dat", "a");
  82.  
  83.     for (x1=0;x1<5;x1=x1+1)
  84.         {
  85.             if ((high_score_sphere.new_high[x1] == true) || (high_score_time.new_high[x1] == true))
  86.                 save_high_score = true;
  87.         }
  88.  
  89.     if (save_high_score == true)
  90.         {
  91.             fprintf(stream, "%s=%.2f=%.2f=%.2f=%.2f=%.2f\n", high_score_name, paddle_object[Compete].score,
  92.                 paddle_object[Compete].time_lapse_score,
  93.                 paddle_object[Compete].score * paddle_object[Compete].time_lapse_score * 230.0f,
  94.                 paddle_object[Compete].score * paddle_object[Compete].time_lapse_score * 320.0f,
  95.                 paddle_object[Compete].score / paddle_object[Compete].time_lapse_score,
  96.                 paddle_object[Compete].time_lapse_score / paddle_object[Compete].score);
  97.         }
  98.  
  99.     fclose(stream);
  100. }
  101.  
  102. /***************************************************************************/
  103.  
  104. void Show_High_Scores(bool color_menu)
  105.  
  106. {
  107.     float    y_position = -60.0f;
  108.     int        x1;
  109.  
  110.     window.Font_Char("                                          SECONDS", -265.0f, -20.0f, 10.0f, R_1, G_1, B_1);
  111.     window.Font_Char("SPHERES                                     IN", -265.0f, -30.0f, 10.0f, R_1, G_1, B_1);
  112.     window.Font_Char("ALLOWED                                   BETWEEN", -265.0f, -40.0f, 10.0f, R_1, G_1, B_1);
  113.  
  114.     window.Font_Char("          SECONDS", -265.0f, -20.0f, 10.0f, R_7, G_7, B_7);
  115.     window.Font_Char("            IN                                      SPHERES", -265.0f, -30.0f, 10.0f, R_7, G_7, B_7);
  116.     window.Font_Char("          BETWEEN                                   ALLOWED", -265.0f, -40.0f, 10.0f, R_7, G_7, B_7);
  117.     window.Font_Char("------------------                        ------------------", -265.0f, -50.0f, 10.0f, R_1, G_1, B_1);
  118.  
  119.     for (x1=0;x1<5;x1=x1+1)
  120.         {
  121.             if ((high_score_sphere.new_high[x1] == true) && (color_menu == true))
  122.                 {
  123.                     window.Font_Int(high_score_sphere.spheres[x1], -255.0f, y_position, 10.0f, R_8, G_8, B_8);
  124.                     window.Font_Float(high_score_sphere.time[x1], 2, -198.0f, y_position, 10.0f, R_8, G_8, B_8);
  125.                     window.Font_Char(high_score_sphere.name[x1], -130.0f, y_position, 10.0f, R_8, G_8, B_8);
  126.                 }
  127.             else
  128.                 {
  129.                     window.Font_Int(high_score_sphere.spheres[x1], -255.0f, y_position, 10.0f, R_1, G_1, B_1);
  130.                     window.Font_Float(high_score_sphere.time[x1], 2, -198.0f, y_position, 10.0f, R_7, G_7, B_7);
  131.                     window.Font_Char(high_score_sphere.name[x1], -130.0f, y_position, 10.0f, R_7, G_7, B_7);
  132.                 }
  133.  
  134.             if ((high_score_time.new_high[x1] == true) && (color_menu == true))
  135.                 {
  136.                     window.Font_Float(high_score_time.time[x1], 2, 12.0f, y_position, 10.0f, R_8, G_8, B_8);
  137.                     window.Font_Int(high_score_time.spheres[x1], 88.0f, y_position, 10.0f, R_8, G_8, B_8);
  138.                     window.Font_Char(high_score_time.name[x1], 145.0f, y_position, 10.0f, R_8, G_8, B_8);
  139.                 }
  140.             else
  141.                 {
  142.                     window.Font_Float(high_score_time.time[x1], 2, 12.0f, y_position, 10.0f, R_1, G_1, B_1);
  143.                     window.Font_Int(high_score_time.spheres[x1], 88.0f, y_position, 10.0f, R_7, G_7, B_7);
  144.                     window.Font_Char(high_score_time.name[x1], 145.0f, y_position, 10.0f, R_7, G_7, B_7);
  145.                 }
  146.  
  147.             y_position = y_position - 10.0f;
  148.         }
  149. }
  150.  
  151. /***************************************************************************/
  152.  
  153. void Sort_High_Score_Sphere()
  154.  
  155. {
  156.     High_Score_Struct    temp;
  157.     int                                sorted_index[6];
  158.     int                                x1;
  159.  
  160.     // Initialize temp and sorted_index;
  161.     temp = high_score_sphere;
  162.     for (x1=0;x1<6;x1=x1+1)
  163.         sorted_index[x1] = x1;
  164.  
  165.     // Add the new score to position [5]
  166.     strncpy(high_score_sphere.name[5], high_score_name, 20);
  167.     high_score_sphere.new_high[5] = true;
  168.     high_score_sphere.spheres[5] = (int)(paddle_object[Compete].score);
  169.     high_score_sphere.time[5] = paddle_object[Compete].time_lapse_score;
  170.  
  171.     // Sort indexes
  172.     qsort(sorted_index, 6, sizeof(int), Compare_High_Score_Sphere);
  173.  
  174.     // Copy the sorted values to temp
  175.     for (x1=0;x1<6;x1=x1+1)
  176.         {
  177.             strncpy(temp.name[x1], high_score_sphere.name[sorted_index[x1]], 15);
  178.             temp.new_high[x1] = high_score_sphere.new_high[sorted_index[x1]];
  179.             temp.spheres[x1] = high_score_sphere.spheres[sorted_index[x1]];
  180.             temp.time[x1] = high_score_sphere.time[sorted_index[x1]];
  181.             temp.name[x1][15] = '\0';
  182.         }
  183.  
  184.     // Copy the sorted values back
  185.     high_score_sphere = temp;
  186. }
  187.  
  188. /***************************************************************************/
  189.  
  190. void Sort_High_Score_Time()
  191.  
  192. {
  193.     High_Score_Struct    temp;
  194.     int                                sorted_index[6];
  195.     int                                x1;
  196.  
  197.     // Initialize temp and sorted_index;
  198.     temp = high_score_time;
  199.     for (x1=0;x1<6;x1=x1+1)
  200.         sorted_index[x1] = x1;
  201.  
  202.     // Add the new score to position [5]
  203.     strncpy(high_score_time.name[5], high_score_name, 20);
  204.     high_score_time.new_high[5] = true;
  205.     high_score_time.spheres[5] = (int)(paddle_object[Compete].score);
  206.     high_score_time.time[5] = paddle_object[Compete].time_lapse_score;
  207.  
  208.     // Sort indexes
  209.     qsort(sorted_index, 6, sizeof(int), Compare_High_Score_Time);
  210.  
  211.     // Copy the sorted values to temp
  212.     for (x1=0;x1<6;x1=x1+1)
  213.         {
  214.             strncpy(temp.name[x1], high_score_time.name[sorted_index[x1]], 15);
  215.             temp.new_high[x1] = high_score_time.new_high[sorted_index[x1]];
  216.             temp.spheres[x1] = high_score_time.spheres[sorted_index[x1]];
  217.             temp.time[x1] = high_score_time.time[sorted_index[x1]];
  218.             temp.name[x1][15] = '\0';
  219.         }
  220.  
  221.     // Copy the sorted values back
  222.     high_score_time = temp;
  223. }
  224.  
  225. /***************************************************************************/